-
Notifications
You must be signed in to change notification settings - Fork 1.6k
GH-3930: Add Jackson 3 support; deprecate Jackson 2 #3996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Fixes: spring-projects#3930 * Manage dependencies, similar way we do for Jackson 2 * Add Jackson 3 counterparts for existing Jackson 2 based classes (mostly copy/paste) * Deprectate Jackson 2 classes * Update tests * Initial round of updates in docs Signed-off-by: Soby Chacko <[email protected]>
*/ | ||
public DefaultJacksonKafkaHeaderMapper(String... patterns) { | ||
this(JsonMapper.builder() | ||
.findAndAddModules(JacksonJsonMessageConverter.class.getClassLoader()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class loader from this class exactly, not something else to avoid class tangle and so.
* Create an instance for inbound mapping only with pattern matching. | ||
* @param patterns the patterns to match. | ||
* @return the header mapper. | ||
* @since 2.8.8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No @since
on methods in all new classes, please.
Object value = decodeValue(header, type); | ||
headers.put(header.key(), value); | ||
} | ||
catch (IOException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be revised since Jackson 3 does not throw IOException
any more.
May just catch (Exception e) {
instead?
@@ -101,6 +103,9 @@ public BatchMessagingMessageConverter(@Nullable RecordMessageConverter recordCon | |||
if (JacksonPresent.isJackson2Present()) { | |||
this.headerMapper = new DefaultKafkaHeaderMapper(); | |||
} | |||
else if (JacksonPresent.isJackson3Present()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's prefer Jackson 3!
If they have both in classpath, so Jackson 3 choice would win.
* On the producer side, select a subclass that matches the corresponding | ||
* Kafka Serializer. | ||
* | ||
* @author Soby Chacko |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, honor authors of class we are deprecating.
|
||
private JacksonJavaTypeMapper typeMapper = new DefaultJacksonJavaTypeMapper(); | ||
|
||
private final TypeFactory typeFactory = TypeFactory.createDefaultInstance(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use ObjectMapper.getTypeFactory()
instead in the ctor!
import org.springframework.util.Assert; | ||
|
||
/** | ||
* A {@link MessageConverter} implementation based on Jacthat uses a Spring Data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably meant based on Jackson 3
😄
@@ -263,6 +265,13 @@ project ('spring-kafka') { | |||
exclude group: 'org.jetbrains.kotlin' | |||
} | |||
|
|||
optionalApi 'tools.jackson.core:jackson-databind' | |||
optionalApi 'tools.jackson.datatype:jackson-datatype-joda' | |||
optionalApi 'tools.jackson.dataformat:jackson-dataformat-xml' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't do XML here in Spring Kafka, so let's just remove this redundant dependency!
Fixes: #3930